package com.jiezuo.auth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiezuo.auth.entity.Depart;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @description 部门信息
 * @author 王帅
 * @date 2020/08/04 16:56
 * @version V1.0
 **/
public interface DepartMapper extends BaseMapper<Depart> {

    List<Map<String, String>> findUserDepart();

    @Select("SELECT  " +
            " DISTINCT sd.*   " +
            "FROM  " +
            " sys_depart sd " +
            "LEFT JOIN sys_depart_user sdu ON sd.id=sdu.depart_id AND sd.is_delete=0  " +
            "WHERE " +
            " sdu.user_id=#{userId} " +
            "ORDER BY sd.sort ASC,sd.id ASC")
    List<Depart> findDepartsByUserId(String user_id);

    List<Depart> findDepartById(@Param("id")String id);

    List<Depart> findAllList(@Param("entity")Depart depart);

    List<Depart> findGather();

    @Update("UPDATE sys_depart  SET is_institute=#{depart.is_institute}, code=#{depart.code},  name=#{depart.name}, pid=#{depart.pid}, status=#{depart.status}, sort=#{depart.sort}, " +
            " is_branch=#{depart.is_branch},  main_leader=#{depart.main_leader}, affiliation_enterprise=#{depart.affiliation_enterprise}, " +
            " is_project_contract_statistic=#{depart.is_project_contract_statistic}, ancestors=#{depart.ancestors}, updated_by=#{depart.updated_by}, updated_time=now(), " +
            " is_abandon=#{depart.is_abandon}, is_2025_version=#{depart.is_2025_version}, level=#{depart.level}, section=#{depart.section}, is_delete=0  WHERE id=#{depart.id}")
    int updateDepart(@Param("depart") Depart depart);

}
